home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / util / libs / graphics3d.lha / src / library / graphics3Dsu.c < prev   
Encoding:
C/C++ Source or Header  |  1999-02-16  |  8.3 KB  |  315 lines

  1. /*
  2. **      $VER: StartUp.c 37.16 (23.8.97)
  3. **
  4. **      Library startup-code and function table definition
  5. **
  6. **      (C) Copyright 1996-97 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <exec/libraries.h>
  13. #include <exec/execbase.h>
  14. #include <exec/resident.h>
  15. #include <exec/initializers.h>
  16.  
  17. #include <proto/exec.h>    /* all other compilers */
  18.  
  19. #include "graphics3Dc.h"
  20.  
  21. #include "graphics3Dbase.h"
  22. #include "graphics3D2D.h"
  23. #include "graphics3Df.h"
  24. #include "graphics3dl.h"
  25.  
  26. extern ULONG L_OpenLibs(void);
  27. extern void  L_CloseLibs(void);
  28.  
  29. struct Graphics3DBase *InitLib( REG(a6) struct ExecBase *sysbase,
  30.                     REG(a0) struct SegList *seglist,
  31.                     REG(d0) struct Graphics3DBase *exb );
  32.  
  33. struct Graphics3DBase *OpenLib( REG(a6) struct Graphics3DBase *ExampleBase);
  34.  
  35. APTR CloseLib( REG(a6) struct Graphics3DBase *Graphics3DBase );
  36.  
  37. APTR ExpungeLib( REG(a6) struct Graphics3DBase *exb);
  38.  
  39. ULONG ExtFuncLib(void);
  40.  
  41.  
  42. /* -------------------------------------------------------------------------
  43.  ! LibStart:
  44.  !
  45.  ! If someone tries to start a library as an executable, it must return 
  46.  ! (LONG) -1 as result. That's what we are doing here.
  47.  ------------------------------------------------------------------------ */
  48.  
  49. LONG LibStart(void)
  50. {
  51.  return(-1);
  52. }
  53.  
  54.  
  55. /* -------------------------------------------------------------------------
  56.  ! Function and Data Tables:
  57.  !
  58.  ! The function and data tables have been placed here for traditional 
  59.  ! reasons.
  60.  ! Placing the RomTag structure before (-> LibInit.c) would also be a good 
  61.  ! idea, but it depends on whether you would like to keep the "version" 
  62.  ! stuff separately.
  63.  ------------------------------------------------------------------------ */
  64.  
  65. extern APTR FuncTab [];
  66. extern struct MyDataInit DataTab; 
  67. /* instead you may place ROMTag + Datatab directly, here */
  68. /* (see LibInit.c). This may fix "Installer" version     */
  69. /* checking problems, too.                               */
  70.  
  71. struct InitTable                       /* do not change */
  72. {
  73.  ULONG              LibBaseSize;
  74.  APTR              *FunctionTable;
  75.  struct MyDataInit *DataTable;
  76.  APTR               InitLibTable;
  77. } InitTab =
  78. {
  79.  sizeof(struct Graphics3DBase),
  80.  &FuncTab[0],
  81.  &DataTab,
  82.  InitLib
  83. };
  84.  
  85. APTR FuncTab [] =
  86. {
  87.  OpenLib,
  88.  CloseLib,
  89.  ExpungeLib,
  90.  ExtFuncLib,
  91.  
  92. /* add your own functions here */
  93.  
  94. /* pubbliche */
  95. /* for compatibility , don't change never the order of this functions */
  96. /* add the new one after the last **/
  97.  GD_switch_rp,
  98.  GD_clipbox,
  99.  GD_cls_b,
  100.  GD_over,
  101.  GD_display3d,
  102.  GD_close_display3d,
  103.  GD_changeviewmode,
  104.  GD_changeviewmodeobj,
  105.  GD_touchpalette,
  106.  GD_moveforward,
  107.  GD_viewangle,
  108.  GD_frustum,
  109.  GD_createlightsource,
  110.  GD_ambientlight,
  111.  GD_positioncamera,
  112.  GD_aspectratio,
  113.  GD_clipmode,
  114.  GD_newobj,
  115.  GD_deleteobject,
  116.  GD_addobjvertex,
  117.  GD_addobjpoly,
  118.  GD_cattpoly,
  119.  GD_setobj,
  120.  GD_getobj,
  121.  GD_translateobject,
  122.  GD_positionobject,
  123.  GD_scaleobject,
  124.  GD_rotateobject,
  125.  GD_pickobj,
  126.  GD_rgb4,
  127.  GD_paintframe,
  128.  GD_newview,
  129.  GD_recalcobj,
  130.  GD_cascene,
  131.  GD_int2fix,
  132.  GD_fix2int,
  133.  GD_sfl2fix,
  134.  GD_fix2sfl,
  135.  GD_dfl2fix,
  136.  GD_fix2dfl,
  137.  GD_loadobject,
  138.  GD_genpalette,
  139.  GD_modpoly,
  140.  GD_newtmap,
  141.  GD_rmtmap,
  142.  GD_newtmapf,
  143.  GD_colldetect,
  144.  GD_modobj,
  145.  
  146. /* add the new one from here **/
  147.  
  148. /* private */
  149.  
  150. /* tappo */
  151.  (APTR) ((LONG)-1)
  152. };
  153.  
  154.  
  155. extern struct Graphics3DBase *Graphics3DBase;
  156.  
  157. /* -------------------------------------------------------------------------
  158.  ! InitLib:
  159.  !
  160.  ! This one is single-threaded by the Ramlib process. Theoretically you can 
  161.  ! do, what you like here, since you have full exclusive control over all 
  162.  ! the library code and data.
  163.  ! But due to some bugs in Ramlib V37-40, you can easily cause a deadlock 
  164.  ! when opening certain libraries here (which open other libraries, that 
  165.  ! open other libraries, that...)
  166.  ------------------------------------------------------------------------ */
  167.  
  168. struct Graphics3DBase *InitLib( REG(a6) struct ExecBase *sysbase,
  169.                     REG(a0) struct SegList *seglist,
  170.                     REG(d0) struct Graphics3DBase *exb)
  171. {
  172.  Graphics3DBase = exb;
  173.  
  174.  Graphics3DBase->exb_SysBase = sysbase;
  175.  Graphics3DBase->exb_SegList = seglist;
  176.  
  177.  if(L_OpenLibs()) return(Graphics3DBase);
  178.  
  179.  L_CloseLibs();
  180.  
  181.   {
  182.    ULONG negsize, possize, fullsize;
  183.    UBYTE *negptr = (UBYTE *) Graphics3DBase;
  184.  
  185.    negsize  = Graphics3DBase->exb_LibNode.lib_NegSize;
  186.    possize  = Graphics3DBase->exb_LibNode.lib_PosSize;
  187.    fullsize = negsize + possize;
  188.    negptr  -= negsize;
  189.  
  190.    FreeMem(negptr, fullsize);
  191.  
  192.   }
  193.  
  194.  return(NULL);
  195. }
  196.  
  197. /* -------------------------------------------------------------------------
  198.  ! OpenLib:
  199.  !
  200.  ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a 
  201.  ! Wait() call would break this Forbid/Permit(), you are not allowed to 
  202.  ! start any operations that may cause a Wait() during their processing. 
  203.  ! It's possible, that future OS versions won't turn the multi-tasking off, 
  204.  ! but instead use semaphore protection for this function.
  205.  !
  206.  ! Currently you only can bypass this restriction by supplying your own 
  207.  ! semaphore mechanism.
  208.  ------------------------------------------------------------------------ */
  209.  
  210. struct Graphics3DBase *OpenLib( REG(a6) struct Graphics3DBase *ExampleBase)
  211. {
  212.  
  213.  Graphics3DBase->exb_LibNode.lib_OpenCnt++;
  214.  
  215.  Graphics3DBase->exb_LibNode.lib_Flags &= ~LIBF_DELEXP;
  216.  
  217.  return(Graphics3DBase);
  218. }
  219.  
  220. /* -------------------------------------------------------------------------
  221.  ! CloseLib:
  222.  !
  223.  ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a 
  224.  ! Wait() call would break this Forbid/Permit(), you are not allowed to 
  225.  ! start any operations that may cause a Wait() during their processing. 
  226.  ! It's possible, that future OS versions won't turn the multi-tasking off, 
  227.  ! but instead use semaphore protection for this function.
  228.  !
  229.  ! Currently you only can bypass this restriction by supplying your own 
  230.  ! semaphore mechanism.
  231.  ------------------------------------------------------------------------ */
  232.  
  233. APTR CloseLib( REG(a6) struct Graphics3DBase *Graphics3DBase )
  234. {
  235.  Graphics3DBase->exb_LibNode.lib_OpenCnt--;
  236.  
  237.  if(!Graphics3DBase->exb_LibNode.lib_OpenCnt)
  238.   {
  239.    if(Graphics3DBase->exb_LibNode.lib_Flags & LIBF_DELEXP)
  240.     {
  241.      return( ExpungeLib(Graphics3DBase) );
  242.     }
  243.   }
  244.  
  245.  return(NULL);
  246. }
  247.  
  248. /* -------------------------------------------------------------------------
  249.  ! ExpungeLib:
  250.  !
  251.  ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a 
  252.  ! Wait() call would break this Forbid/Permit(), you are not allowed to 
  253.  ! start any operations that may cause a Wait() during their processing. 
  254.  ! It's possible, that future OS versions won't turn the multi-tasking off, 
  255.  ! but instead use semaphore protection for this function.
  256.  !
  257.  ! Currently you only could bypass this restriction by supplying your own 
  258.  ! semaphore mechanism - but since expunging can't be done twice, one 
  259.  ! should avoid it here.
  260.  ------------------------------------------------------------------------ */
  261.  
  262. APTR ExpungeLib( REG(a6) struct Graphics3DBase *exb )
  263. {
  264.  struct Graphics3DBase *Graphics3DBase = exb;
  265.  struct SegList *seglist;
  266.  
  267.  if(!Graphics3DBase->exb_LibNode.lib_OpenCnt)
  268.   {
  269.    ULONG negsize, possize, fullsize;
  270.    UBYTE *negptr = (UBYTE *) Graphics3DBase;
  271.  
  272.    seglist = Graphics3DBase->exb_SegList;
  273.  
  274.    Remove((struct Node *)Graphics3DBase);
  275.  
  276.    L_CloseLibs();
  277.  
  278.    negsize  = Graphics3DBase->exb_LibNode.lib_NegSize;
  279.    possize  = Graphics3DBase->exb_LibNode.lib_PosSize;
  280.    fullsize = negsize + possize;
  281.    negptr  -= negsize;
  282.  
  283.    FreeMem(negptr, fullsize);
  284.  
  285.    return(seglist);
  286.   }
  287.  
  288.  Graphics3DBase->exb_LibNode.lib_Flags |= LIBF_DELEXP;
  289.  
  290.  return(NULL);
  291. }
  292.  
  293. /* -------------------------------------------------------------------------
  294.  ! ExtFunct:
  295.  !
  296.  ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a 
  297.  ! Wait() call would break this Forbid/Permit(), you are not allowed to 
  298.  ! start any operations that may cause a Wait() during their processing. 
  299.  ! It's possible, that future OS versions won't turn the multi-tasking off, 
  300.  ! but instead use semaphore protection for this function.
  301.  !
  302.  ! Currently you only can bypass this restriction by supplying your own 
  303.  ! semaphore mechanism - but since this function currently is unused, you 
  304.  ! should not touch it, either.
  305.  ------------------------------------------------------------------------ */
  306.  
  307. ULONG ExtFuncLib(void)
  308. {
  309.  return(NULL);
  310. }
  311.  
  312. struct Graphics3DBase *Graphics3DBase = NULL;
  313.  
  314.  
  315.